package com.abel.bigwater.data.mapper

import com.abel.bigwater.data.jnrq.JnrqDevice
import com.alibaba.fastjson.JSON
import org.junit.Test

import org.junit.Assert.*
import org.junit.FixMethodOrder
import org.junit.runner.RunWith
import org.junit.runners.MethodSorters
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.context.annotation.ComponentScan
import org.springframework.test.context.junit4.SpringRunner

@SpringBootTest(classes = [DeviceTemplateTest::class])
@RunWith(SpringRunner::class)
@ComponentScan(basePackages = ["com.abel.bigwater.data"])
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
class DeviceTemplateTest {

    @Autowired
    var dt: DeviceTemplate? = null

    @Test
    fun test11AddDevice() {
        val jd = JnrqDevice().apply {
            address = "12345"
        }

        try {
            dt!!.insertJnrqDevice(jd)
        } finally {
            val dr = dt!!.removeJnrqDevice(jd)
            lgr.info("delete result: {}", JSON.toJSONString(dr, true))
        }
    }

    @Test
    fun test12FindJnrqDevice() {
        val list = dt!!.findJnrqDeviceList()
        lgr.info("jnrq-device list: {}", JSON.toJSONString(list, true))
    }

    companion object {
        private val lgr = LoggerFactory.getLogger(DeviceTemplateTest::class.java)
    }
}